import 'dart:async';

import 'package:amap_flutter_map/amap_flutter_map.dart';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:amap_flutter_base/amap_flutter_base.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

class AppGdMap extends StatefulWidget {
  final AppGdMapPoint? point;

  const AppGdMap({super.key, this.point});

  @override
  State<AppGdMap> createState() => _AppGdMapState();
}

class AppGdMapPoint {
  final String icon;
  final LatLng latLng;

  AppGdMapPoint({required this.icon, required this.latLng});
}

class _AppGdMapState extends State<AppGdMap> {
  Map<String, Marker> _initMarkerMap = <String, Marker>{};

  late AMapController mapController;

  // 获取审图号
  void getApprovalNumber() async {
    //普通地图审图号
    String? mapContentApprovalNumber =
        await mapController?.getMapContentApprovalNumber();
    //卫星地图审图号
    String? satelliteImageApprovalNumber =
        await mapController?.getSatelliteImageApprovalNumber();
  }

  AMapApiKey _amapApiKeys = AMapApiKey(
      androidKey: '37c7d80606950366447621bbb9681459',
      iosKey: '6dd47940595825dba26017b739221982');

  AMapPrivacyStatement _amapPrivacyStatement =
      AMapPrivacyStatement(hasContains: true, hasShow: true, hasAgree: true);

  _onMapCreated(AMapController controller) {
    setState(() {
      mapController = controller;
      getApprovalNumber();
    });
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    if (widget.point != null) {
      _initMarkerMap['xx'] = Marker(position: widget.point!.latLng);
      setState(() {});
    }
  }

  @override
  Widget build(BuildContext context) {
    return AMapWidget(
      privacyStatement: _amapPrivacyStatement,
      apiKey: _amapApiKeys,
      onMapCreated: _onMapCreated,
      initialCameraPosition:
          CameraPosition(target: widget.point!.latLng, zoom: 14),
      markers: Set<Marker>.of(_initMarkerMap.values),
    );
  }
}
